﻿<%@ Page Language="C#" MasterPageFile="~/U_masterP.master" AutoEventWireup="true"
    CodeFile="collection.aspx.cs" Inherits="collectionPage" %>                                                                          
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Register Src="uc_main/sideBar_right.ascx" TagName="sideBar_right" TagPrefix="uc1" %>
<%@ Register Src="uc_main/menu_canhan.ascx" TagName="menu_canhan" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <style>
        #content_left2
        {
            width: 100%;
            margin: 0px 0px;
            float: left;
            position: relative;
            min-height: 700px;
        }
    </style>
    <div id="content_top">
    
        <div id="kep">
            <a href="#">Trang cá nhân</a></div>
        <div id="tags">
            <div id="result">
            </div>
            <% if (Session["KhachHang"] != null)
               { %>
            <div id="Iwill">
                Tôi sẽ
                <asp:TextBox ID="TextBox1" CssClass="txtTieptuc" Width="400px" runat="server" MaxLength="200"></asp:TextBox>
                chỉ với 5$.
                <ajaxToolkit:FilteredTextBoxExtender ID="TextBox1_FilteredTextBoxExtender" runat="server"
                    FilterMode="InvalidChars" InvalidChars="!@#$%^&amp;*()_-+=\|{}[]&quot;':,&lt;&gt;.?/"
                    TargetControlID="TextBox1">
                </ajaxToolkit:FilteredTextBoxExtender>
                <div id="btn_tieptuc">
                    <asp:Button ID="btnTiep2" CssClass="tieptuc" runat="server" OnClientClick="return checkTT()"
                        Text="Tiếp tục" OnClick="btnTiep2_Click" /></div>
            </div>
            <% }
               else { } %>
        </div>
      
    </div>
    <div class="clear">
    </div>
    <div id="sub_content">
        <div id="content_left2">
            <!-- noi dung chinh -->
            <uc2:menu_canhan ID="menu_canhan1" runat="server" />
            <input type="hidden" runat="server" id="hdGig" />
            <div class="box">
                <div class="linkEdit">
                    <div class="dacbiet" style="float: right; margin-bottom: 5px">
                        <a href="#collection-create" name="signup" rel="leanModal" id="collection-modal">thêm
                            mới</a>
                        <%-- <asp:LinkButton ID="linkAdd" runat="server" OnClick="linkAdd_Click">Thêm mới</asp:LinkButton>
                        <asp:Literal ID="Literal1" runat="server"></asp:Literal>--%>
                    </div>
                </div>
            </div>
            <div id="main_canhan">
                <asp:Repeater runat="server" ID="GridView1">
                    <HeaderTemplate>
                        <div class="datalist-item datalist-item-first ">
                            <div class="datalist-item-date" style="width: 60%">
                                <b>Tên</b>
                            </div>
                            <div class="datalist-item-title" style="width: 20%">
                                <b>Ngày tạo</b>
                            </div>
                        </div>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div class="datalist-item">
                            <div class="datalist-item-date" style="width: 60%">
                                <a href="collectionDetail.aspx?idCollection=<%#Eval("idCollection") %>"><span class="collection-name" id="<%#Eval("idCollection") %>">
                                    <%#Eval("Name") %></span></a>
                            </div>
                            <div class="datalist-item-title" style="width: 20%">
                                <%#string.Format("{0:dd/MM/yyyy}",Eval("TimeInput")) %>
                            </div>
                            <div class="datalist-item-status">
                                <a class="collection-delete" id="collection_<%#Eval("idCollection") %>" href="<%#Eval("idCollection") %>">
                                    Xóa</a>
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
           
            </div>
        </div>
    </div>
    <div id="collection-create">
        <div id="signup-ct">
            <div id="signup-header">
                <h2 style="color: Red; display: none;text-align:center;text-transform:uppercase" id="messageSuccessCollectionModal">
                   Thêm dữ liệu thành công
                </h2>
                <h2 style="text-align: center; text-transform: uppercase; color: #AAAAAA">
                    Thêm mới bộ sưu tập</h2>
                <%--  <a href="" class="modal_close"></a>--%>
            </div>
            <div class="txt-fld" style="margin: 5px 0; padding: 5px">
                <label for="">
                    Tên bộ sưu tập</label>
                <input style="width: 270px" type="text" id="txtNameCollection" />
                <span style="color: red" id="txtNameCollectionError"></span>
            </div>
            <div class="btn-fld">
                <%--   <span style="color: Red">(*)</span> không được trống--%>
                <button type="button" id="btnCollectionSubmit">
                    Gửi</button>
                <button type="button" id="btnCollectionReset">
                    Làm lại</button>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $(function () {
                $('#collection-modal').leanModal({ top: 230, closeButton: ".modal_close" });
            });
            $("#btnCollectionReset").live("click", function () {
                $("#txtNameCollection").val("");
                $("#txtNameCollection").focus();
            })
            $("#btnCollectionSubmit").live("click", function () {
                var tenCollection = $("#txtNameCollection").val();
                if (tenCollection == null || tenCollection == "") {
                    $("#txtNameCollectionError").text("(*)");
                    $("#txtNameCollection").focus();
                    return false;
                }
                else
                    $("#txtNameCollectionError").text("");
                $.ajax({
                    type: "POST",
                    url: "collection.aspx/InsertCollectionModal",
                    data: '{collectionName: "' + tenCollection + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (response.d == 0) {
                            alert("Có lỗi xảy ra, vui lòng thực hiện lai");
                        }
                        else if (response.d == -1) {
                            alert("Tên bộ sưu tập đã có !!!");
                            $("#txtNameCollection").focus();
                        }
                        else {
                            $("#messageSuccessCollectionModal").show();
                            setTimeout(function () {
                                $("#lean_overlay").fadeOut(200);
                                $("#collection-create").css({ "display": "none" });
                                $("#txtNameCollection").val("");
                                DisplayCollection(response.d);
                            }, 1000);
                        }
                    },
                    failure: function (response) {
                        alert("Có lỗi xảy ra, vui lòng thực hiện lai");
                    }
                });

                return false;
            })
            function DisplayCollection(id) {
                $.ajax({
                    type: "POST",
                    url: "collection.aspx/SelectCollectionModal",
                    data: '{id: "' + id + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        var item = response.d;
                        if (item != null) {
                            $("#main_canhan div:first").after("<div class='datalist-item'><div style='width:60%' class='datalist-item-date'>" + item.Name + "</div>" + "<div style='width: 20%' class='datalist-item-title'>" + item.TimeInput + "</div><div class='datalist-item-status'>" + "<a href='" + item.Id + "' id='collection_" + item.Id + "' class='collection-delete'>" + " Xóa </a> </div></div>");
                            //$("#main_canhan div:first").append("<div class='datalist-item'><div style='width:60%' class='datalist-item-date'>" + item.Name + "</div>" + "<div style='width: 20%' class='datalist-item-title'>" + item.TimeInput + "</div><div class='datalist-item-status'>" + "<a href='" + item.Id + "' id='collection_" + item.Id + "' class='collection-delete'>" + " Xóa </a> </div></div>");
                        }
                        else {
                            alert("Có lỗi xảy ra, vui lòng thực hiện lai");
                        }
                    },
                    failure: function (response) {
                        alert("Có lỗi xảy ra, vui lòng thực hiện lai");
                    }
                });
            }

            //$(".collection-delete").click(function () {
            $(".collection-delete").live("click", function () {
                var answer = confirm('Bạn muốn xóa bộ sưu tập này?');
                if (answer) {
                    //lay id cua thẻ a đang dc click
                    var id = $(this).attr("id");
                    //  $("#img-loading").show();
                    $.ajax({
                        type: "POST",
                        url: "collection.aspx/DeleteCollection",
                        data: '{id: "' + $(this).attr("href") + '" }',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        // success: OnSuccess(id),
                        success: function (response) {
                            if (response.d == 0) {
                                alert("Có lỗi xảy ra, vui lòng thực hiện lai");
                                //$("#img-loading").hide();
                            }
                            else if (response.d == 1) {
                                //$("#img-loading").hide();
                                $("#" + id).parent().parent().remove();
                            }

                        },
                        failure: function (response) {
                            alert("Có lỗi xảy ra, vui lòng thực hiện lai");
                            //$("#img-loading").hide();
                        }
                    });
                }
                return false;
            });

            function checkTT() {
                if ($('.txtTieptuc').val() == "") {
                    alert('Không được để trống ');
                    $('.txtTieptuc').focus();
                    return false;
                }
            }
            //            $(".collection-name").live("click", function () {
            //                var idGig = $("#<%=hdGig.ClientID %>").val();
            //                if (idGig != null && idGig != "") {
            //                    var idCollection = $(this).attr("id");
            //                    $.ajax({
            //                        type: "POST",
            //                        url: "collection.aspx/InsertCollectionDetail",
            //                        data: '{idCollection: "' + idCollection + '"' + ',idGig:"' + idGig + '" }',
            //                        contentType: "application/json; charset=utf-8",
            //                        dataType: "json",
            //                        // success: OnSuccess(id),
            //                        success: function (response) {
            //                            if (response.d == 0) {
            //                                alert("Có lỗi xảy ra, vui lòng thực hiện lai");
            //                                //$("#img-loading").hide();
            //                            }
            //                            else if (response.d == 1) {
            //                                //$("#img-loading").hide();
            //                                //$("#" + id).parent().parent().remove();
            //                                alert("Đã thêm thành công");
            //                            }

            //                        },
            //                        failure: function (response) {
            //                            alert("Có lỗi xảy ra, vui lòng thực hiện lai");
            //                            //$("#img-loading").hide();
            //                        }
            //                    });
            //                }
            //            })
        })
    </script>
</asp:Content>
